#include "MovementData.h"

namespace binge
{

MovementData::MovementData(void)
{

}

MovementData::~MovementData(void)
{
    objectsVelocity.clear();
    objectsMoveTimer.clear();
    objectsMoveStart.clear();
}

void
MovementData::AddObject(int id)
{
    Vector3 vect;

    objectsId.push_back(id);
    objectsVelocity.push_back(vect);
    objectsMoveTimer.push_back(16); // 30 FPS (32ms) 60 FPS (16ms)
    objectsMoveStart.push_back(0);
}

void
MovementData::RemoveObject(int id)
{
    int index = GetIndex(id);
    objectsId.erase(objectsId.begin()+index);
    objectsVelocity.erase(objectsVelocity.begin()+index);
    objectsMoveTimer.erase(objectsMoveTimer.begin()+index);
    objectsMoveStart.erase(objectsMoveStart.begin()+index);
}

Vector3
MovementData::GetVelocity(int id)
{
    Vector3 temp;
    int index = GetIndex(id);
    if (index != -1)
    {
        temp = objectsVelocity[index];
    }
    return temp;
}

void
MovementData::SetVelocity(int id, Vector3 vel)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsVelocity[index] = vel;
    }
}

void
MovementData::SetVelocity(int id, float x, float y)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsVelocity[index].Set(x,y,0);
    }
}

float
MovementData::GetXVelocity(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsVelocity[index].GetX();
    }
    return -1;
}

float
MovementData::GetYVelocity(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsVelocity[index].GetY();
    }
    return -1;
}

void
MovementData::SetXVelocity(int id, float x)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsVelocity[index].SetX(x);
    }
}

void
MovementData::SetYVelocity(int id, float y)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsVelocity[index].SetY(y);
    }
}

void
MovementData::SetMoveTimer(int id, unsigned int ms)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsMoveTimer[index] = ms;
    }
}

unsigned int
MovementData::GetMoveTimer(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsMoveTimer[index];
    }
    return 0;
}

void
MovementData::SetMoveStart(int id, unsigned int ms)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsMoveStart[index] = ms;
    }
}

unsigned int
MovementData::GetMoveStart(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsMoveStart[index];
    }
    return 0;
}

} // namespace
